/*
 * @Author: Y先森
 * @Date: 2023-04-20 15:33:09
 * @LastEditors: y && 250048395@qq.com
 * @LastEditTime: 2023-04-20 16:03:53
 * @FilePath: \y-website\src\utils\theme.js
 */
import store from '@/store'
import { watch } from 'vue'
import { THEME_LIGHT, THEME_DARK } from '@/constants'

/**
 * 变更主题
 * @param {*} theme 主题的标记常量
 */
const changeTheme = (theme) => {
    console.log('theme=>',theme)
    // html 的 class
    let themeClassName = ''
    switch (theme) {
        case THEME_LIGHT:
          themeClassName = 'light'
          break
        case THEME_DARK:
          themeClassName = 'dark'
          break
      }
    // 修改 html 的 class
    console.log(themeClassName)
    document.querySelector('html').className = themeClassName
}

/**
 * 初始化主题
 */
export default () => {
    watch(() => store.getters.themeType, changeTheme, {
      // 初始执行一次
      immediate: true
    })
  }